package cn.task.config;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.pinecone.PineconeEmbeddingStore;
import dev.langchain4j.store.embedding.pinecone.PineconeServerlessIndexConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置向量存储对象
 @author Mengru Jiao
 @date 2025/5/29
 @project java-ai-langchain4j
 */
@Configuration
public class EmbeddingStoreConfig {
    @Autowired
    private EmbeddingModel embeddingModel;
    @Bean
    public EmbeddingStore<TextSegment> embeddingStore(){
        EmbeddingStore<TextSegment> embeddingStore = PineconeEmbeddingStore.builder()
                .apiKey(System.getenv("PINECONE_API_KEY"))
                .index("xiaozhi-index")
                .nameSpace("xiaozhi-namespace").
                //指定索引部署在 AWS 云服务上。
                        createIndex(PineconeServerlessIndexConfig.builder().cloud("AWS")
                        //指定索引所在的 AWS 区域为 us-east-1。
                        .region("us-east-1")
                        //指定索引的向量维度，该维度与embeddedModel 生成的向量维度相同。)
                        .dimension(embeddingModel.dimension()).build()).build();
        return embeddingStore;
    }

}
